import 'package:enjoy_plus/pages/house/building_list.dart';
import 'package:enjoy_plus/pages/house/house_detail.dart';
import 'package:enjoy_plus/pages/house/house_form.dart';
import 'package:enjoy_plus/pages/house/house_list.dart';
import 'package:enjoy_plus/pages/house/location_list.dart';
import 'package:enjoy_plus/pages/house/room_list.dart';
import 'package:enjoy_plus/pages/login/index.dart';
import 'package:enjoy_plus/pages/notice/index.dart';
import 'package:enjoy_plus/pages/profile/index.dart';
import 'package:enjoy_plus/pages/tab_bar_page.dart';
import 'package:enjoy_plus/utils/token.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(MaterialApp(
    routes: {
      '/': (context) => const TabBarPage(),
      '/detail': (context) => const NoticeDetail(),
    },
    onGenerateRoute: (settings) {
      final token = TokenManager().getToken();
      if (token == null) {
        // 如果没有token，则跳转到登录页面
        return MaterialPageRoute(builder: (context) => const LoginPage());
      }
      if (settings.name == '/profile') {
        return MaterialPageRoute(
            builder: (context) => ProfilePage(info: settings.arguments as Map));
      }
      // 我的房屋
      if (settings.name == '/house_list') {
        return MaterialPageRoute(builder: (context) => const HouseList());
      }
      // 添加房屋
      if (settings.name == '/location_list') {
        return MaterialPageRoute(builder: (context) => const LocationList());
      }
      if (settings.name == '/building_list') {
        return MaterialPageRoute(
            builder: (context) =>
                BuildingList(point: (settings.arguments as Map)['point']));
      }
      if (settings.name == '/room_list') {
        Map temp = settings.arguments as Map;
        return MaterialPageRoute(
            builder: (context) => RoomList(
                  point: temp['point'],
                  building: temp['building'],
                ));
      }
      if (settings.name == '/house_form') {
        return MaterialPageRoute(
            builder: (context) => HouseForm(
                  params: settings.arguments as Map,
                ));
      }
      if (settings.name == '/house_detail') {
        return MaterialPageRoute(
            builder: (context) =>
                HouseDetail(id: (settings.arguments as Map)['id']));
      }
      return null;
    },
    initialRoute: '/',
  ));
}
